import axios from "axios"

//如果在发送来自其他域的XMLHttpRequest请求之前，未设置withCredentials 为true，那么就不能为它自己的域设置cookie值。
//而通过设置withCredentials 为true获得的第三方cookies，将会依旧享受同源策略，因此不能被通过document.cookie或者从头部相应请求的脚本等访问。

axios.defaults.withCredentials = true

export const shoppinglist =(x,y) =>axios.get('https://elm.cangdu.org/shopping/restaurants?latitude='+x+'&longitude='+y);

export  const orderList = (id)=>axios.get("https://elm.cangdu.org/bos/v2/users/"+id+"/orders?limit=10&offset=0")

export const getCity = (type) => {
    return axios.get("https://elm.cangdu.org/v1/cities?type="+type)
}

export const getCheckCity =(cityid)=>{
    return axios.get("https://elm.cangdu.org/v1/cities/"+cityid)
}

export const searchAddress =(cityid,keyword)=>{
    return axios.get(`https://elm.cangdu.org/v1/pois?city_id=${cityid}&keyword=${keyword}&type=search`)
}

export const getCheckoutImg =()=>{
    return axios.post(`https://elm.cangdu.org/v1/captchas`)
}

export const getLogin = (data) => {
    return axios({
        url:"https://elm.cangdu.org/v2/login",
        method:"post",
        data,
      
    })
}

export const isLogin =() =>{
    return axios.get("https://elm.cangdu.org/v1/user")
}

export const loggout =() =>{
    return axios.get("https://elm.cangdu.org/v2/signout")
}

export const editPassword= (data) => {
    return axios({
        url:"https://elm.cangdu.org/v2/changepassword",
        method:"post",
        data,
      
    })
}
// 新增收货地址的地址详情
export const getDetailAddress = (keyword) => {
    return axios.get(`https://elm.cangdu.org/v1/pois?keyword=${keyword}&type=nearby`)
}

export const plusAddress= (data) => {
    return axios({
        url:"https://elm.cangdu.org/v1/users/"+data.user_id+"/addresses",
        method:"post",
        data,
      
    })
}

//获取用户收货地址
export const getUserAddress =(uid)=>{
    return axios.get("https://elm.cangdu.org/v1/users/"+uid+"/addresses")
}

//

export const delUserAddress =(uid,id)=>{
    return axios.delete("https://elm.cangdu.org/v1/users/"+uid+"/addresses/"+id)
}




export const getflxq = () => {    //获取商品分类列表
    return axios.get("https://elm.cangdu.org/shopping/v2/restaurant/category")
}

// export const getfldp = (data) => {    //商品分类获取店铺
//     console.log(data)
//     let {latitude,longitude,id,order} =data
//     if(data.flag){
//         return axios.get("http://elm.cangdu.org/shopping/restaurants?latitude="+latitude+"&longitude="+longitude+"&restaurant_category_id="+id+"&order_by="+order)
//     }else{
//         return axios.get("http://elm.cangdu.org/shopping/restaurants?latitude="+latitude+"&longitude="+longitude+"&restaurant_category_ids[]="+id+"&order_by="+order)
//     }
    
// }
export const getfldp = (data) => {    //商品分类获取店铺
    console.log(data)
    let {latitude,longitude,id,order} =data
  
    
   
        return axios.get("http://elm.cangdu.org/shopping/restaurants?latitude="+latitude+"&longitude="+longitude+"&restaurant_category_ids[]="+id+"&order_by="+order)
   
    
}